package com.quad.innovators.salesease.enums;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.quad.innovators.salesease.exception.BusinessException;

import java.util.HashMap;
import java.util.Map;

import lombok.Getter;

/**
 * @author : shanshan.li
 * @createTime : 2025/4/7 22:40
 * @Version : 1.0 
 */
@Getter
public enum VehicleBringScanTypeEnum {

    SHIPPING(1, "出货"),
    RETURN(2, "回货"),
    MANY(3, "多货"),
    LACK(4, "少货");

    private final Integer code;
    private final String description;

    VehicleBringScanTypeEnum(Integer code, String description) {
        this.code = code;
        this.description = description;
    }

    static final Map<Integer, VehicleBringScanTypeEnum> map = new HashMap<>();

    static {
        VehicleBringScanTypeEnum[] values = values();
        for (VehicleBringScanTypeEnum vehicleBringScanTypeEnum : values) {
            map.put(vehicleBringScanTypeEnum.code, vehicleBringScanTypeEnum);
        }
    }

    public static VehicleBringScanTypeEnum useCodeGetEnum(Integer code) {
        VehicleBringScanTypeEnum vehicleBringScanTypeEnum = map.getOrDefault(code, null);
        if (ObjectUtils.isNull(vehicleBringScanTypeEnum)) {
            throw BusinessException.resultCode(ResultCode.NOT_FOUND);
        }
        return vehicleBringScanTypeEnum;
    }
}
